package com.hinnotek.amoeba.viewmodels


import androidx.lifecycle.viewModelScope
import com.hinnotek.amoeba.base.BaseBean
import com.hinnotek.amoeba.bean.old.*
import com.hinnotek.amoeba.repo.AmibaRepo
import com.lee.common.base.BaseViewModel
import com.lee.common.network.net.StateLiveData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import okhttp3.RequestBody
import javax.inject.Inject

@HiltViewModel
class AmibaViewModel @Inject constructor(private val repository: AmibaRepo) :
    BaseViewModel() {

    private val amibaTemporaryeByIdData = StateLiveData<AmibaTemporaryeByIdBean>()
    private val sellPurchaseRequistionDetailData = StateLiveData<SellPurchaseRequistionDetailBean>()
    private val sellPurchaseRequistionData =
        StateLiveData<MutableList<SellPurchaseRequistionBean>>()
    private val basedata = StateLiveData<BaseBean>()
    private val basedata2 = StateLiveData<BaseBean>()
    private val basedata3 = StateLiveData<BaseBean>()
    private val basedata4 = StateLiveData<BaseBean>()
    private val basedata5 = StateLiveData<BaseBean>()
    private val basedata6 = StateLiveData<BaseBean>()

    fun getAmibaTemporaryeById(amibaTemporaryId: Int): StateLiveData<AmibaTemporaryeByIdBean> {
        viewModelScope.launch {
            repository.getAmibaTemporaryeById(amibaTemporaryId, amibaTemporaryeByIdData)
        }
        return amibaTemporaryeByIdData
    }

    fun getAmibaPurchaseById(amibaPurchaseId: Int): StateLiveData<SellPurchaseRequistionDetailBean> {
        viewModelScope.launch {
            repository.getAmibaPurchaseById(amibaPurchaseId, sellPurchaseRequistionDetailData)
        }
        return sellPurchaseRequistionDetailData
    }

    fun updateAmibaPurchase(requestBody: RequestBody): StateLiveData<BaseBean> {
        viewModelScope.launch {
            repository.updateAmibaPurchase(requestBody, basedata)
        }
        return basedata
    }

    fun backAmibaPurchase(amibaPurchaseId: Int): StateLiveData<BaseBean> {
        viewModelScope.launch {
            repository.backAmibaPurchase(amibaPurchaseId, basedata2)
        }
        return basedata2
    }

    fun resubmitAmibaPurchase(amibaPurchaseId: Int): StateLiveData<BaseBean> {
        viewModelScope.launch {
            repository.resubmitAmibaPurchase(amibaPurchaseId, basedata3)
        }
        return basedata3
    }

    fun getAmibaPurchaseType1ByUserId(requestBody: RequestBody): StateLiveData<MutableList<SellPurchaseRequistionBean>> {
        viewModelScope.launch {
            repository.getAmibaPurchaseType1ByUserId(requestBody, sellPurchaseRequistionData)
        }
        return sellPurchaseRequistionData
    }

    fun getAmibaPurchaseType2ByUserId(requestBody: RequestBody): StateLiveData<MutableList<SellPurchaseRequistionBean>> {
        viewModelScope.launch {
            repository.getAmibaPurchaseType2ByUserId(requestBody, sellPurchaseRequistionData)
        }
        return sellPurchaseRequistionData
    }

    fun getAmibaPurchaseType3ByUserId(requestBody: RequestBody): StateLiveData<MutableList<SellPurchaseRequistionBean>> {
        viewModelScope.launch {
            repository.getAmibaPurchaseType3ByUserId(requestBody, sellPurchaseRequistionData)
        }
        return sellPurchaseRequistionData
    }

    fun addAmibaTemporary(requestBody: RequestBody): StateLiveData<BaseBean> {
        viewModelScope.launch {
            repository.addAmibaTemporary(requestBody, basedata4)
        }
        return basedata4
    }

    private val amibaTemporaryePageByUserIdData =
        StateLiveData<MutableList<AmibaTemporaryePageByUserIdBean>>()

    fun getAmibaTemporaryePageByUserId(requestBody: RequestBody): StateLiveData<MutableList<AmibaTemporaryePageByUserIdBean>> {
        viewModelScope.launch {
            repository.getAmibaTemporaryePageByUserId(requestBody, amibaTemporaryePageByUserIdData)
        }
        return amibaTemporaryePageByUserIdData
    }


    fun addAmibaPurchaseSale(requestBody: RequestBody) :StateLiveData<BaseBean>{
        viewModelScope.launch {
            repository.addAmibaPurchaseSale(requestBody, basedata5)
        }
        return basedata5
    }

    fun addAmibaPurchaseTechnology(requestBody: RequestBody) :StateLiveData<BaseBean>{
        viewModelScope.launch {
            repository.addAmibaPurchaseTechnology(requestBody, basedata5)
        }
        return basedata5
    }

    fun addAmibaPurchaseDevelop(requestBody: RequestBody): StateLiveData<BaseBean> {
        viewModelScope.launch {
            repository.addAmibaPurchaseDevelop(requestBody, basedata5)
        }
        return basedata5
    }

    fun updateAmibaPurchaseProject(requestBody: RequestBody) :StateLiveData<BaseBean>{
        viewModelScope.launch {
            repository.updateAmibaPurchaseProject(requestBody, basedata6)
        }
        return basedata6
    }


}